home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / sphigs / sph_mac.hqx / SRGP port to 5.0 (compressed) / SRGP_SPHIGS Root / MacSPHIGS / sph_intense.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-13  |  2.0 KB  |  63 lines

  1. #include "HEADERS.h"
  2. /**********************
  3.                       *
  4.  File                 * intensity.c
  5.                       * calculates intensity for each object
  6.                       *
  7.                       * takes the list of objects and calculates Gouraud
  8.                       *    intensities (flat shading)
  9.                       * 
  10.                       * changes objects intensity
  11.                       * needs to be called after clip (to get the bounds)
  12.               *
  13.                       *********************************************************/
  14.  
  15. /**********************
  16.                       *
  17.  Includes          *
  18.                       *
  19.                       *********************************************************/
  20.  
  21. #include <stdio.h>
  22. #include "sphigslocal.h"
  23. #include <assert.h>
  24.  
  25. #include "sph_intense.proto.h"
  26.  
  27.  
  28. /**********************
  29.                       *
  30.  Function          * calc_intensity
  31.                       *
  32.                       * calculates the intensity for each object
  33.               *
  34.                       *********************************************************/
  35. void SPH__calc_intensity (view_spec *vs)
  36. {
  37.      MAT3hvec negatedVector;
  38.      MAT3hvec centerFace;
  39.      MAT3hvec oddNormal;
  40.      register obj *scanObj;
  41.      double temp;
  42.      
  43.      scanObj = vs->objects;
  44.      
  45.      while (scanObj != NULL) {
  46.       if (scanObj->type == objFace) {
  47.            centerFace[X] = ( scanObj->max[X] + scanObj->min[X] ) / 2;
  48.            centerFace[Y] = ( scanObj->max[Y] + scanObj->min[Y] ) / 2;
  49.            centerFace[Z] = ( scanObj->max[Z] + scanObj->min[Z] ) / 2;
  50.            centerFace[3] = 1;
  51.            MAT3_SUB_VEC (negatedVector, 
  52.                  vs->uvn_point_light_source, centerFace );
  53.            negatedVector[3] = 1;
  54.            MAT3_NORMALIZE_VEC( negatedVector, temp );
  55.            MAT3_COPY_VEC ( oddNormal, scanObj->normal );
  56.            oddNormal[3] = 1;
  57.            MAT3_NORMALIZE_VEC( oddNormal, temp );
  58.            scanObj->intensity = MAT3_DOT_PRODUCT(negatedVector, oddNormal );
  59.       }
  60.       scanObj = scanObj->next;
  61.      }
  62. }
  63.